(function(){

        var argu = getArgu();
        
        
       if(navigator.userAgent.indexOf('webull') < 0 && navigator.userAgent.indexOf('stocks') < 0){
            if(argu.sp==1){//显示stocks的ad
            	
            }else{
	            $('#download-tip').css('display','block');
	            $('#download-tip .close').on('click',function(){
	                $('#download-tip').css('display','none');
	            });
          }
        }
        
       // stocks's open
        var isStocksOpen = (navigator.userAgent.indexOf('stocks') > 0 || argu.sp==1);
          
        var stockArr = [];
        var curHeight;

        var _id = 1;

        if (argu.style == 0 || argu.theme == 2){
            $('body').removeClass('style-2');
        }else{
        		$('body').addClass('style-2');
        }

        if (argu.color == 3) {
            $('body').addClass('color-3');
        } else if (argu.color == 2) {
            $('body').addClass('color-2');
        } else {
            $('body').addClass('color-1');
        }


        function getArgu(){

            var _url = location.href;
            var num = _url.indexOf('?');
            var str = _url.substr(num+1);
            var arr = [];
            var argus = [];
            arr = str.split('&');
            var obj = {};
            for (var i = 0; i < arr.length; i++) {
                argus = arr[i].split('=');
                obj[argus[0]] = argus[1];
            }
            return obj;
        }

        vlang =argu.hl;
        if (vlang == undefined){
            vlang = "en";
        }
       var v_attach =argu.attach;


        //拉取相关股票
        if(isStocksOpen == false){
	        $.ajax({
	            url : app_cneter_news_md5_url + url_md5 +"?hl="+vlang+"&attach="+v_attach,
	            dataType : 'jsonp',
	            jsonpCallback : 'callback',

	            success:function(data){

	               if (data) {

	                    stockArr = data;
	                    var _data = {}

	                    _data.content = data;

	                    var html;
	                    html = template('stock-detail', _data);
	                    $('.rela-stocks').html(html);

	                    var contRel = $('.stock-relative');
	                    var _height = contRel.find('.stock-area').height();

	                    if (_height > 86) {
	                        curHeight = 85;
	                        contRel.height(85);
	                    }else {
	                        $('.trig').find('i').remove();
	                        curHeight = _height-1;
	                        contRel.height(_height-1);
	                    }
	                } else {

	                }
	            },
	            error:function(){

	            }
	        });
       }
        var wrap = $('#news');


        wrap.on('tap', '.trig', function(event) {
            event.preventDefault();

            if (curHeight < 85) {
                return false;
            }

            var _this = $(this);
            var item = _this.parent('.rela-stocks');
            var contRel = item.find('.stock-relative');
            var contRelHeight = contRel.height();
            var realCont = contRel.find('.stock-area');
            var _height = realCont.height();
            var _arrow = _this.find('i');
            var _speed = 300;

            if (!item.hasClass('active') && contRelHeight == curHeight) {
                contRel.animate({
                    height: _height-1 + 'px',
                }, _speed);
                _arrow.animate({
                    transform : 'rotate(180deg)'
                }, _speed)

                setTimeout(function(){
                    item.addClass('active');
                },_speed);
            }else if(item.hasClass('active') && contRelHeight == _height-1){
                contRel.animate({
                    height: '85px'
                }, _speed);
                _arrow.animate({
                    transform : 'rotate(0deg)'
                }, _speed)

                setTimeout(function(){
                    item.removeClass('active');
                },_speed);

            }else{
                return;
            }
        });

        wrap.on('tap', '.stock', function(event) {
            event.preventDefault();

            var _this = $(this);
            var _index = _this.index();

            skipStock(JSON.stringify(stockArr[_index]));
        });

        function skipStock(context) {
            var isAndroid = /(Android)/i.test(navigator.userAgent); //android终端
            var isiOS = /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent); //ios终端
            if(isAndroid){
                if(window.WebullApp){
               		 window.WebullApp.openRelatedStock(context);
                }else{
                	var obj = JSON.parse(context);
	                window.webViewBridge.callHandler(
	                    "related_ticker",
	                    obj,
	                    function (responseData) {
	                         var str = JSON.stringify(responseData);
	                    }
	                );
              }
           }else if(isiOS){
               window.webkit.messageHandlers.Action.postMessage(context);
          }
      }

  

    })();

    function shareNews(){
      	var obj = {};obj.title = $('#id_title').html()  || '';obj.url = window.location.href  || '';obj.general = $('#id_general').html() || '';
      	var isAndroid = /(Android)/i.test(navigator.userAgent); //android终端
        var isiOS = /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent); //ios终端
      //  alert(JSON.stringify( obj ));
        var context = JSON.stringify(obj);
        if(isAndroid){
            window.WebullApp.setShareData(context);
        }else{
					 window.webkit.messageHandlers.NewsShare.postMessage(context);
        }
      }


	  (function(i,s,o,g,r,a,m){
		  i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
		  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
		  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
	  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-91649277-1', 'auto');
  ga('send', 'pageview');